package itsur.arquitecturas.implicitinvocation;

/**************************************************************************************
** Class name: List		
** Author: A.J. Lattanze
** Date: 12/29/99
** Version 1.0
***************************************************************************************
** Purpose: Assignment 3 for SE 17-655, Architectures for Software Systems.  This is 
** the base class that is used to construct the StudentList and the CoursesList 
** objects.  The storage mechanism used is the Java Vector found in the java.util 
** package.
** (reused from assignment 2)
**
** Abstract: A vector object is declared a several generic operations are defined for 
** the List class:
**
**	void AppendItemToList( Object )	- Adds an object to the list
**	void GoToFrontOfList()			- Sets the VectorIndex to the front of the list
**	Object GetItemFromList()		- Returns the object pointed to by the 
**							  VectorIndex. If null is returned, its the end
**							  of the list.
** 
** The detailed function of each of these methods is listed below in the code.
**
** Modification Log
**************************************************************************************
**
**************************************************************************************/

import java.util.*;

public class List
{
	Vector ItemList;	// Allocates 25 elements initially and will 
				// extend the vector by elements of 5
	int VectorIndex;	// Used to index elements in the list


	List()
	{
		ItemList = new Vector (25, 5);
		VectorIndex = 0;

	} // Constructor

	/*******************************************************************************
	** This method simply uses the Vector.add method to append the Object to the end
	** of the list.  Casting from Object to specific class is handled in the classes
	** that extend this class.
	*******************************************************************************/

	public void AppendItemToList( Object Item )
	{
		ItemList.add( Item );

	} // Append Item

	/*******************************************************************************
	** This method will get the Object from the list that is currently being pointed 
	** to by VectorIndex. Casting from Object to specific class is handled in the 
	** classes that extend this class.
	*******************************************************************************/

	public Object GetItemFromList()
	{	
		Object ListItem;
	
		// Each time we get an item we increment the VectorIndex
		// If we go out of the Vector bounds, then we will catch
		// in the the catch clause below and return a null object

		try 
		{
			ListItem = ItemList.get(VectorIndex);
			VectorIndex ++;
			return( ListItem );

		} // try
		
		catch ( ArrayIndexOutOfBoundsException error )
		{
			return( (Object) null );

		} // if 

	} // Append Item

	/*******************************************************************************
	** This sets VectorIndex back to zero, thereby pointing at the front of the 
	** list. 
	*******************************************************************************/

	void GoToFrontOfList()
	{	
		VectorIndex = 0;

	} // Append Item

} // List Class